package com.journaldev.spring.model;

import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name="chitiet_toathuoc")
@AssociationOverrides({
		@AssociationOverride(name = "pk.medicine", 
			joinColumns = @JoinColumn(name = "id_thuoc")),
		@AssociationOverride(name = "pk.prescription", 
			joinColumns = @JoinColumn(name = "id_toathuoc")) })
public class PrescriptionMedicine {
	
	public PrescriptionMedicine() {}
	
	public PrescriptionMedicine(PrescriptionMedicineId pk,
			int numberOfMedicine) {
		super();
		this.pk = pk;
		this.soluong = numberOfMedicine;
	}

	private PrescriptionMedicineId pk = new PrescriptionMedicineId();
	
	@Column(name="soluong")
	private int soluong;
	
	public int getSoluong() {
		return soluong;
	}

	public void setSoluong(int soluong) {
		this.soluong = soluong;
	}
	
	@Column(name="cachsudung")
	private String cachsudung;

	public String getCachsudung() {
		return cachsudung;
	}

	public void setCachsudung(String cachsudung) {
		this.cachsudung = cachsudung;
	}

	@EmbeddedId
	public PrescriptionMedicineId getPk() {
		return pk;
	}
 
	public void setPk(PrescriptionMedicineId pk) {
		this.pk = pk;
	}
	
	@Transient
	public Medicine getMedicine() {
		return getPk().getMedicine();
	}
 
	public void setMedicine(Medicine med) {
		getPk().setMedicine(med);
	}
 
	@Transient
	public Prescription getPrescription() {
		return getPk().getPrescription();
	}
	
	public void setPrescription(Prescription pres) {
		getPk().setPrescription(pres);
	}
	
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;
 
		PrescriptionMedicine that = (PrescriptionMedicine) o;
 
		if (getPk() != null ? !getPk().equals(that.getPk())
				: that.getPk() != null)
			return false;
 
		return true;
	}
 
	public int hashCode() {
		return (getPk() != null ? getPk().hashCode() : 0);
	}

}
